using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using DG.Tweening;
using UnityEngine;

public class BuffManager : singleTon<BuffManager>
{
    public List<Buff> CurrentBuffTimeList = new List<Buff>();
    


    private void Update()
    {
       CalucateBuffTime();
    }

    public void SetDamageBuff(float value, float buffTime,GameObject effect)
    {
        var characterStates = GameManager.Instance.playerStats;
        CurrentBuffTimeList[0].Value = value;
        CurrentBuffTimeList[0].TemplateBuffTime = buffTime;
        CurrentBuffTimeList[0].effect = effect;
        CurrentBuffTimeList[0].isBuffing = true;
        characterStates.attackData.maxDamage += CurrentBuffTimeList[0].Value;
        characterStates.attackData.minDamage += CurrentBuffTimeList[0].Value;
    }
    
    
    
    public void CalucateBuffTime()
    {
        for (int i = 0; i < CurrentBuffTimeList.Count; i++)
        {
            if (CurrentBuffTimeList[i].isBuffing)
            {
                CurrentBuffTimeList[i].currentBuffTime += Time.deltaTime;
                if (CurrentBuffTimeList[i].currentBuffTime >= CurrentBuffTimeList[i].TemplateBuffTime)
                {
                    CurrentBuffTimeList[i].isBuffing = false;
                    CurrentBuffTimeList[i].currentBuffTime = 0;
                    var characterStates = GameManager.Instance.playerStats;
                    switch(CurrentBuffTimeList[i].buffType)
                    {
                        case BuffType.Damage:
                            characterStates.attackData.maxDamage -= CurrentBuffTimeList[i].Value;
                            characterStates.attackData.minDamage -= CurrentBuffTimeList[i].Value;
                            Destroy(CurrentBuffTimeList[0].effect);
                            break;
                        case BuffType.Denfense:
                            characterStates.characterData.baseDefence -=(int)CurrentBuffTimeList[i].Value;
                            break;
                            
                    }
                }
            }
        }
    }
}
